import request from "@/utils/request";

export interface EmployeeData {
  id: number;
  username: string;
  realName: string;
  role: string;
  phone: string;
  email: string;
  status: number;
  createTime: string;
}

export interface EmployeeQuery {
  page: number;
  size: number;
  keyword?: string;
}

export interface EmployeeForm {
  id?: string;
  username: string;
  password?: string;
  realName: string;
  role: string[];
  phone: string;
  email: string;
  status: number;
  nickname: string;
  avatarUrl: string;
  gender: number;
  birthday: string;
}

// 获取员工列表
export function getEmployeeList(employeeFrom) {
  return request({
    url: `/users/${employeeFrom.page}/${employeeFrom.size}?message=${employeeFrom.message}&gender=${employeeFrom.gender}&status=${employeeFrom.status}`,
    method: "get"
  });
}

// 添加员工
export function addEmployee(data: EmployeeForm) {
  return request({
    url: "/users",
    method: "post",
    data
  });
}

// 更新员工信息
export function updateEmployee(data: EmployeeForm) {
  return request({
    url: `/employee/update/${data.id}`,
    method: "put",
    data
  });
}

// 删除员工
export function deleteEmployee(id: number) {
  return request({
    url: `/employee/delete/${id}`,
    method: "delete"
  });
}

// 更新员工状态
export function updateEmployeeStatus(id: number, status: number) {
  return request({
    url: `/employee/status/${id}`,
    method: "put",
    data: { status }
  });
}

// 员工角色详情
export function getEmployeeRoleDetail() {
  return request({
    url: `/userRole/getRole`,
    method: "get"
  });
}
